//使用axios封装一个项目的request
import axios from "axios";

const instance = axios.create({
    baseURL: 'http://rap2api.taobao.org/app/mock/276399'
})

instance.interceptors.request.use(config => {
    config.data = Object.assign({},config.data,{
        // authToken: window.localStorage.getItem('authToken');
        authToken: 'itisatokenlacehoder'

    })
    // console.log(config);
    return config;

}, error => {
    console.log(error);
});

instance.interceptors.response.use(res => {
    return res.data;
}, err => {
    if(err && err.response){
        switch (err.response.status) {
            case 400:
                console.log("请求错误");
                break;
            case 401:
                console.log("未经授权");
                break;
            default:
                console.log("其他错误信息");
        }
    }
    return err;
});

export default  instance;